package com.onemore.task.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.voovan.tools.log.Logger;

import com.alibaba.fastjson.JSONObject;
import com.onemore.task.JdbcGlobal;

public class ModelShangpin_A extends JdbcGlobal{
	public final static String shangpin_a_field[] = new String[] {"SPDM","YPMC","DHDM","GHSDM","GHSMC",
    		"LXML","MLMC","THML","MLMC2","DHAO","FK","MLCF","KHAO","KSHI","DJ","DJ1","BYZD3","BYZD4"};
    /**
     * 插入商品
     * @param json
     * @return
     * @throws SQLException 
     */
    static public boolean insert(JSONObject json) throws SQLException
    {
    	String fieldStr = "";
    	String valuesStr = "";
    	String updateStr = "";

    	List<String> listFields = new ArrayList<String>();

    	int i = 0;
    	for(i=0;i<shangpin_a_field.length;i++) {
    		if(json.containsKey(shangpin_a_field[i]))
    			listFields.add(shangpin_a_field[i]);
    	}
    	for(i=0;i<listFields.size()-1;i++) {
    		fieldStr += listFields.get(i)+",";
    		valuesStr += "'"+json.getString(listFields.get(i))+"',";
    		updateStr += listFields.get(i)+"='"+json.getString(listFields.get(i))+"',";
    	}
		fieldStr += listFields.get(i);
		valuesStr += "'"+json.getString(listFields.get(i))+"'";
		updateStr += listFields.get(i)+"='"+json.getString(listFields.get(i))+"'";
		//delete("SHANGPIN",shangpin_a_field[0]+"='"+json.getString(shangpin_a_field[0])+"'");
    	String sql = "";
		if(search("SHANGPIN_A", shangpin_a_field[0]+"='"+json.getString(shangpin_a_field[0])+"'")) {
			updateDate("SHANGPIN_A",shangpin_a_field[0]+"='"+json.getString(shangpin_a_field[0])+"'",updateStr);
		}else {
	        //查询测试
	        sql = "insert into SHANGPIN_A ("+fieldStr+") values("+valuesStr+")";
	        Map<String, Object> map = null;
			Logger.debug(sql);
			getJdbcOperate().update(sql);
		}
		return true;
    }
}
